package com.hzhr.iot.device.convertor.custom;

import com.hzhr.iot.device.convertor.IotDeviceConvertor;
import com.hzhr.iot.device.entity.ext.CollectDeviceEntityExt;
import com.hzhr.iot.device.entity.ext.IotDeviceEntityExt;
import com.hzhr.iot.device.entity.ext.IotDeviceTypeEntityExt;
import com.hzhr.iot.device.entity.ext.OptionsEntityExt;
import com.hzhr.iot.device.model.iotDevice.IotDeviceModel;
import com.hzhr.iot.device.model.pressureMonitor1.PressureMonitor1Model;
import org.springframework.stereotype.Service;

@Service
public class IotDeviceCustomConvertor extends IotDeviceConvertor {
    @Override
    public IotDeviceModel ext2iotDeviceModel(IotDeviceEntityExt in) {
        IotDeviceModel result = super.ext2iotDeviceModel(in);

        OptionsEntityExt ext1 = in.getBindStatusExt();
        if (ext1 != null) {
            result.setBindStatusDes(ext1.getDes());
        }

        OptionsEntityExt ext2 = in.getReportPeriodExt();
        if (ext2 != null) {
            result.setReportPeriodDes(ext2.getDes());
        }

        OptionsEntityExt ext3 = in.getSimTypeExt();
        if (ext3 != null) {
            result.setSimTypeDes(ext3.getDes());
        }

        IotDeviceTypeEntityExt ext4 = in.getTypeExt();
        if (ext4 != null) {
            result.setTypeDes(ext4.getDes());
        }

        return result;
    }

    @Override
    public PressureMonitor1Model ext2pressureMonitor1Model(IotDeviceEntityExt in) {
        PressureMonitor1Model result = super.ext2pressureMonitor1Model(in);
        CollectDeviceEntityExt ext1 = in.getCollectDeviceExt();
        if (ext1 != null) {
            result.setInstallAddress(ext1.getInstallAddress());
            result.setUserName(ext1.getGasUserName());
            result.setDeptId(ext1.getDeptId());
        }
        Double longitude = in.getLongitude();
        Double latitude = in.getLatitude();
        if (longitude != null && latitude != null) {
            result.setCoordinate(longitude + "," + latitude);
        }
        return result;
    }
}

